var e = require("../../@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", { value: !0 }),
  (exports.default = void 0);
var a = require("../../@babel/runtime/helpers/regeneratorRuntime"),
  t = require("../../@babel/runtime/helpers/asyncToGenerator"),
  r = require("../../@babel/runtime/helpers/classCallCheck"),
  n = require("../../@babel/runtime/helpers/createClass"),
  o = require("../../@babel/runtime/helpers/get"),
  s = require("../../@babel/runtime/helpers/getPrototypeOf"),
  i = require("../../@babel/runtime/helpers/inherits"),
  c = require("../../@babel/runtime/helpers/createSuper"),
  l = e(require("./BaseMapDataLoader")),
  p = e(require("../common/DeepClone")),
  u = e(require("../Location/LocationHelper")),
  g = (function (e) {
    i(m, e);
    var l,
      g,
      d,
      f,
      h = c(m);
    function m(e) {
      var a;
      return (
        r(this, m),
        ((a = h.call(this, e))._platformConfig = {
          mapUrl:
            "https://model.seeklane.com/store/map/{mapId}/map_export_{mapId}_{tag}.json",
          beaconUrl: "https://ops.seeklane.com/store/ap/{mapId}/aps_{tag}.json",
          roadUrl:
            "https://ops.seeklane.com/store/road/{mapId}/road_{tag}.json",
          panoramaUrl:
            "https://ops.seeklane.com/store/panorama/{mapId}/panorama_{tag}.json",
          locationUrl:
            "https://ops.seeklane.com/store/location/{mapId}/location_{tag}.json",
        }),
        (a._routeTaskList = {}),
        a._allJson,
        a
      );
    }
    return (
      n(m, [
        {
          key: "dataVersion",
          get: function () {
            return this._config.dataVersion || "PROD";
          },
        },
        {
          key: "getPlatformConfig",
          value: function () {
            return this._platformConfig;
          },
        },
        {
          key: "_storeConfigs",
          value:
            ((f = t(
              a().mark(function e(t) {
                var r, n, i;
                return a().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          return (
                            (e.next = 2),
                            o(s(m.prototype), "_storeConfigs", this).call(
                              this,
                              t,
                            )
                          );
                        case 2:
                          if (
                            ((r = this.projectConfig),
                            (n = r.allUrl),
                            (i = r.lastUpdatedTime),
                            !n)
                          ) {
                            e.next = 14;
                            break;
                          }
                          if (((e.prev = 4), this._allJson)) {
                            e.next = 9;
                            break;
                          }
                          return (
                            (e.next = 8), this.ajax({ url: n + "?t=" + i })
                          );
                        case 8:
                          this._allJson = e.sent;
                        case 9:
                          e.next = 14;
                          break;
                        case 11:
                          (e.prev = 11),
                            (e.t0 = e.catch(4)),
                            console.error("all json load error", e.t0);
                        case 14:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                  [[4, 11]],
                );
              }),
            )),
            function (e) {
              return f.apply(this, arguments);
            }),
        },
        {
          key: "_storeBuildingConfigs",
          value: function (e) {
            var a = this,
              t = e.maps,
              r = e.projectMark || {},
              n = r.groundCode,
              o = r.undergroundCode,
              s = {
                MAP: "mapUrl",
                BEACON: "beaconUrl",
                ROAD: "roadUrl",
                PANORAMA: "panoramaUrl",
                LOCATION: "locationUrl",
              },
              i = 0;
            t.forEach(function (t, r) {
              var c = t.mapCode,
                l = t.markers,
                p = t.mapName,
                u = t.mapId,
                g = t.outside || n === c || !1,
                d = t.underground || o === c || !1;
              if ((d && (a._undergroundMapCode = c), t.urls))
                a._cacheConfigs[c] = t;
              else {
                var f = {};
                l.forEach(function (e) {
                  var t = e.code,
                    n = e.type,
                    o = e.tag,
                    c = s[n];
                  if (t === a.dataVersion && c) {
                    var l = a._platformConfig[c];
                    if (l)
                      switch (
                        ((l = (l = l.replace(/\{mapId\}/g, u)).replace(
                          /\{tag\}/g,
                          o,
                        )),
                        c)
                      ) {
                        case "mapUrl":
                          f.map = l;
                          var p = o.replace(/\D/g, ""),
                            g = parseInt(p);
                          Number.isNaN(g) || (i += g << r);
                          break;
                        case "roadUrl":
                          f.road = l;
                          break;
                        case "beaconUrl":
                          f.beacon = l;
                          break;
                        case "panoramaUrl":
                          f.panorama = l;
                          break;
                        case "locationUrl":
                          f.location = l;
                      }
                  }
                }),
                  (f.fp = "https://ops.seeklane.com/store/train/".concat(
                    u,
                    "/fingerprint.json",
                  )),
                  i > 0 && (e.lastUpdatedTime = i);
                var h = { mapId: u, urls: f, mapCode: c, mapName: p };
                a._cacheConfigs[c] = h;
              }
              Object.assign(a._cacheConfigs[c], { outside: g, underground: d }),
                (a._cacheConfigs[c].buildingId = u);
            });
          },
        },
        {
          key: "_getConfigRequest",
          value:
            ((d = t(
              a().mark(function e(t) {
                var r, n, o, s, i, c, l, p, u, g, d;
                return a().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          if (
                            ((r = this.projectUrl
                              ? ""
                                  .concat(this.projectUrl, "/")
                                  .concat(t, "/info.json")
                              : ""
                                  .concat(this.apiHost)
                                  .concat(
                                    this.apiPrefix,
                                    "/basic/getConfig?projectCode=",
                                  )
                                  .concat(t)),
                            !this._originConfig)
                          ) {
                            e.next = 5;
                            break;
                          }
                          (n = this._originConfig), (e.next = 8);
                          break;
                        case 5:
                          return (e.next = 7), this.ajax({ url: r });
                        case 7:
                          n = e.sent;
                        case 8:
                          return (
                            "projectCode" === this.accessMode || this.projectUrl
                              ? ((s = n.data),
                                (i = s.maps),
                                (c = s.configs),
                                (l = s.projectName),
                                (p = s.projectCode),
                                (u = s.lastUpdatedTime),
                                (g = s.allUrl),
                                (o = { maps: i }),
                                c.forEach(function (e) {
                                  var a = e.propertyCode,
                                    t = e.content,
                                    r = JSON.parse(t);
                                  "customConfig" !== a &&
                                    ((r = {})[a] = JSON.parse(t)),
                                    Object.assign(o, r);
                                }),
                                (o.projectName = l),
                                (o.projectCode = p),
                                (o.lastUpdatedTime = u || 1),
                                (o.allUrl = g))
                              : ((d = n.data), (o = { maps: [d] })),
                            e.abrupt("return", { data: o })
                          );
                        case 10:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                );
              }),
            )),
            function (e) {
              return d.apply(this, arguments);
            }),
        },
        {
          key: "getBuildingRP",
          value: function (e, a) {
            var t = (0, p.default)(a);
            return (
              t.forEach(function (a) {
                a.policies.forEach(function (a) {
                  if (a.buildingChangeFloorWaitCost) {
                    var t = a.buildingChangeFloorWaitCost[e];
                    t &&
                      (a.changeFloorWaitCost = Object.assign(
                        {},
                        a.changeFloorWaitCost,
                        t,
                      ));
                  }
                  if (a.buildingChangeFloorFactor) {
                    var r = a.buildingChangeFloorFactor[e];
                    r &&
                      (a.changeFloorFactor = Object.assign(
                        {},
                        a.changeFloorFactor,
                        r,
                      ));
                  }
                });
              }),
              t
            );
          },
        },
        {
          key: "getData",
          value:
            ((g = t(
              a().mark(function e(t, r) {
                var n, o;
                return a().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          if (
                            ((n = t.urls),
                            t.mapName,
                            (o = t.mapCode),
                            !this._allJson)
                          ) {
                            e.next = 5;
                            break;
                          }
                          return e.abrupt("return", this._allJson[o][r]);
                        case 5:
                          return e.abrupt(
                            "return",
                            this.ajax({
                              url:
                                n[r] +
                                "?t=" +
                                (this.projectConfig.lastUpdatedTime || 1),
                            }),
                          );
                        case 6:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                );
              }),
            )),
            function (e, a) {
              return g.apply(this, arguments);
            }),
        },
        {
          key: "_getMapDataRequest",
          value:
            ((l = t(
              a().mark(function e(t) {
                var r, n, o, s, i, c, l, p, g, d;
                return a().wrap(
                  function (e) {
                    for (;;)
                      switch ((e.prev = e.next)) {
                        case 0:
                          if (
                            ((r = t.urls),
                            (n = t.mapName),
                            (o = t.mapCode),
                            (s = {}),
                            !r.map)
                          ) {
                            e.next = 9;
                            break;
                          }
                          return (e.next = 5), this.getData(t, "map");
                        case 5:
                          (i = e.sent), Object.assign(s, i), (e.next = 10);
                          break;
                        case 9:
                          console.error(n + " no target map");
                        case 10:
                          if (!r.road) {
                            e.next = 19;
                            break;
                          }
                          return (e.next = 13), this.getData(t, "road");
                        case 13:
                          (l = e.sent),
                            (c = l.routePolicies),
                            (p = new (u.default.getEngine().cm.v2v1)(l).res),
                            Object.assign(s, p),
                            (e.next = 20);
                          break;
                        case 19:
                          console.warn(n + " no target road");
                        case 20:
                          if (
                            (this.projectConfig.routePolicies &&
                              (c = this.getBuildingRP(
                                o,
                                this.projectConfig.routePolicies,
                              )),
                            Object.assign(s, { routePolicies: c }),
                            !r.beacon)
                          ) {
                            e.next = 29;
                            break;
                          }
                          return (e.next = 25), this.getData(t, "beacon");
                        case 25:
                          (g = e.sent),
                            Object.assign(s, { aps: g }),
                            (e.next = 30);
                          break;
                        case 29:
                          console.warn(n + " no target beacon ap");
                        case 30:
                          if (!r.location) {
                            e.next = 37;
                            break;
                          }
                          return (e.next = 33), this.getData(t, "location");
                        case 33:
                          (d = e.sent),
                            Object.assign(s, { locateOptionsInGraphLayers: d }),
                            (e.next = 38);
                          break;
                        case 37:
                          console.warn(n + " no target location");
                        case 38:
                          return e.abrupt("return", s);
                        case 39:
                        case "end":
                          return e.stop();
                      }
                  },
                  e,
                  this,
                );
              }),
            )),
            function (e) {
              return l.apply(this, arguments);
            }),
        },
      ]),
      m
    );
  })(l.default);
exports.default = g;
